<template>
    <div class="home-classic">
        <h1>经典歌单</h1>
        <div class="wrapper" ref="wrapper">
            <!-- 滚动所需要的容器 -->
            <ul class="content" ref="content">
                <li v-for="(item,index) in listData" :key="index" @click="selectItem(item)">
                    <div class=" cover">
                        <van-image :src="item.cover_url_medium" radius="1rem" />
                        <span>{{item.access_num}}万</span>
                    </div>
                    <span>{{item.title}}</span>
                </li>
            </ul>
        </div>

    </div>
</template>

<script>
import { betterScrollHorizontal } from "../../common/betterScroll.js";
export default {
    data() {
        return {
            listData: [],
            no: 1
        }
    },
    created() {
        this.getData(59, this.no, 10)
    },
    methods: {
        getData(id, pageNo, pageSize) {
            this.$request('get', '/recommend/playlist', {
                id,
                pageNo,
                pageSize
            }).then(res => {
                console.log(res)
                if (res.result == 100) {
                    this.listData = res.data.list;
                }
                // 异步数据的一些处理
                betterScrollHorizontal(
                    this,
                    this.$refs.wrapper,
                    this.$refs.content,
                    this.listData.length,
                    10
                );
            });
        },
        selectItem(item) {
            const id = item.tid;
            // console.log(id)
            //编程式导航，字符串路径的方式
            this.$router.push(`/songlist/${id}`);
        }
    },
    // filters: {
    //     numFilter(value, num) {
    //         return parseFloat(value / 10000).toFixed(num)
    //     }
    // }
}
</script>

<style scoped>
.wrapper {
    width: 100%;
    /* 容器的宽度就是屏幕的宽度 */
    overflow: hidden;
}

ul.content li {
    width: 10rem;
    display: inline-block;
    vertical-align: top;
}

ul.content li * {
    margin: 0 0.1rem;
}

ul.content li>span {
    font-size: 0.8rem;
    color: #625858;
}

.cover {
    position: relative;
}

.cover>span {
    position: absolute;
    right: 0;
    bottom: 0.4rem;
    background-color: #a6a0a0;
    color: white;
    width: 5rem;
    border-radius: 1rem;
}
</style>